<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="vue.js"></script>
    <div id="app">
        <p>{{value}}</p>
        <button @click="change()" >+</button>

        <P>{{price}}</P>
        <button @click="changePrice()" >button</button>
        <p>比原价贵了{{expensive}}</p>

        <p>{{obj.value}}</p>
        <button @click="changeObj"></button>
    </div>

    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                value:100,
                price:100,
                rePrice:100,
                expensive:0,
                obj:{
                    value:1000
                }
            },
            methods:{
                change(){
                    this.value++
                },
                changePrice(){
                    this.price += 10
                },changeObj(){
                    this.obj.value++
                }
            },
            computed:{
                total(){
                    return
                }
            },
            watch:{
                //dataname：function（）{}dataname与监听的数据名字相同
                value(newValue,oldValue){
                    console.log("数据发生了变化")
                    console.log("new" + newValue)
                },
                price(newValue,oldValue){
                    this.expensive = newValue- this.rePrice
                },
                //监听引用类型数据，需要深度监听
                obj:{//深度监听，键值对中value改成对象，里面的键值队是固定的
                    deep:true,  //第一个键值对，deep布尔类型，是深度监听的开关
                    handler(newValue,oldValue){
                        //监听主体
                        //参数是newValue
                        console.log("数据发生了变化");
                        console.log("new" + newValue);
                        console.log("old" + oldValue);
                    },
                    immediate:true
                },
                //深度监听器简写
                "obj.value"(){
                    console.log(1111111);
                },
                //监听计算属性
                total:function(){
                    console.log("计算属性发生了变化");
                }

            }
        })
    </script>
   
</body>

</html>